package com.liyuhang.dao;

import com.liyuhang.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;

    @SuppressWarnings("Duplicates")
    public User findUserByUsername(String username) {
        List<User> users = (List<User>) hibernateTemplate.find("from User where username = ?", username);
        return users.isEmpty()==true?null:users.get(0);
    }
}
